package com.tanhua.dubbo.server.service;

import com.tanhua.dubbo.server.enums.IdType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

/**
 * @Author 王加鑫
 * @Date 2021/09/05 21:42
 * @Since JDK 1.8
 * 生成自增长的id,原理：使用redis的自增长值
 */
@Service
public class IdService {

    @Autowired
    private RedisTemplate<String,String> redisTemplate;

    public Long created(IdType idType){
        String idKey = "TANHUA_ID_" + idType.toString();
        return this.redisTemplate.opsForValue().increment(idKey);
    }

}
